#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int q, n;
int opt[100100];
int inp[100100];
stack<int> s;

void clear() {
    while (!s.empty()) s.pop();
}

int main() {
    cin >> q;
    while (q--) {
        cin >> n;
        for (int i = 0; i < n; i++) cin >> inp[i];
        for (int i = 0; i < n; i++) cin >> opt[i];
        int p = 0, q = 0;
        clear();
        for (p = 0, q = 0; p < n; p++) {
            s.push(inp[p]);
            while (!s.empty() && s.top() == opt[q]) {
                s.pop();
                q++;
            }
        }
        cout << ((p == q) ? "Yes\n" : "No\n");
    }
}